/*
        Firesoft 
        
    Copyright (C) 2010, Arttu Viljakainen 
    Published under GNU General Public License V3 
    (see http://www.gnu.org/licenses/licenses.html)
    
    This file is part of Firesoft.

    Firesoft is free software: 
    you can redistribute it and/or modify it under the terms of the GNU General 
    Public License as published by the Free Software Foundation, 
    either version 3 of the License, or (at your option) any later version.

    Firesoft is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
    Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tool for Path Finding Algorithm Testing. If not, see         
    <http://www.gnu.org/licenses/>.
 */
package softstarter.gui.subareas.settings.itemlist;

import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

import softstarter.launching.RunnableItem;

public class EditableRunnableItem {

	protected RunnableItem item;
	protected JPanel masterContainer;
	
	protected JTextField name;
	protected JTextField path;
	protected JButton removeButton;
	
	public EditableRunnableItem(RunnableItem item) {
		this.item = item;
		build();
	}
	
	private void build() {
		masterContainer = new JPanel();
		masterContainer.setOpaque(false);
		masterContainer.setPreferredSize(new Dimension(375, 35));
		masterContainer.setMaximumSize(new Dimension(375, 35));
		
		name = new JTextField(item.getName());
		name.setPreferredSize(new Dimension(100, 30));
		path = new JTextField(item.getFullPath());
		path.setPreferredSize(new Dimension(220, 30));
		
		removeButton = new JButton("X");
		removeButton.setPreferredSize(new Dimension(40, 25));

		masterContainer.add(name);
		masterContainer.add(path);
		masterContainer.add(removeButton);
	}
	
	public void addRemoveButtonListener(ItemRemoveButtonListenerHandler handler) {
		
		removeButton.addActionListener(new ItemRemoveButtonListener(handler, this));
	}
	
	public JPanel getView() {
		return masterContainer;
	}

	public RunnableItem getItem() {
		return item;
	}

	public JButton getRemoveButton() {
		return removeButton;
	}

	public String getValueFromNameField() {
		return name.getText();
	}

	public String getValueFromPathField() {
		return path.getText();
	}

	public void addChangeListener(EditableRunnableItemChangeListener itemChangeListener) {

		name.addKeyListener(itemChangeListener);
		path.addKeyListener(itemChangeListener);
		
	}
	
}
